package org.dromara.teacher.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.teacher.domain.vo.XjClassInfoVo;
import org.dromara.teacher.domain.bo.XjClassInfoBo;
import org.dromara.teacher.service.IXjClassInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 班级信息
 *
 * @author xjb
 * @date 2024-12-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/teacher/classInfo")
public class XjClassInfoController extends BaseController {

    private final IXjClassInfoService xjClassInfoService;

    /**
     * 查询班级信息列表
     */
    @SaCheckPermission("teacher:classInfo:list")
    @GetMapping("/list")
    public TableDataInfo<XjClassInfoVo> list(XjClassInfoBo bo, PageQuery pageQuery) {
        return xjClassInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出班级信息列表
     */
    @SaCheckPermission("teacher:classInfo:export")
    @Log(title = "班级信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XjClassInfoBo bo, HttpServletResponse response) {
        List<XjClassInfoVo> list = xjClassInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "班级信息", XjClassInfoVo.class, response);
    }

    /**
     * 获取班级信息详细信息
     *
     * @param classId 主键
     */
    @SaCheckPermission("teacher:classInfo:query")
    @GetMapping("/{classId}")
    public R<XjClassInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String classId) {
        return R.ok(xjClassInfoService.queryById(classId));
    }

    /**
     * 新增班级信息
     */
    @SaCheckPermission("teacher:classInfo:add")
    @Log(title = "班级信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XjClassInfoBo bo) {
        return toAjax(xjClassInfoService.insertByBo(bo));
    }

    /**
     * 修改班级信息
     */
    @SaCheckPermission("teacher:classInfo:edit")
    @Log(title = "班级信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XjClassInfoBo bo) {
        return toAjax(xjClassInfoService.updateByBo(bo));
    }

    /**
     * 删除班级信息
     *
     * @param classIds 主键串
     */
    @SaCheckPermission("teacher:classInfo:remove")
    @Log(title = "班级信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{classIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] classIds) {
        return toAjax(xjClassInfoService.deleteWithValidByIds(List.of(classIds), true));
    }
}
